package com.ruoyi.service;

import com.ruoyi.entity.SxfOrderClearingItem;
import com.ruoyi.mapper.SxfOrderClearingItemMapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import com.ruoyi.bean.SxfOrderClearingItemFrom;
import com.sxftech.resp.ResponseData;
/**
 * <p>
 * 订单清分汇总项目表 服务实现类
 * </p>
 *
 * @author liuxing
 * @since 2020-11-09
 */
@Service
public class SxfOrderClearingItemService extends ServiceImpl<SxfOrderClearingItemMapper, SxfOrderClearingItem> {

	public ResponseData create(SxfOrderClearingItemFrom sxfOrderClearingItem) {
		SxfOrderClearingItem entity = transformationFrom(sxfOrderClearingItem);
		this.save(entity);
		return ResponseData.success("新增成功");
	}
	
	public ResponseData modify(SxfOrderClearingItemFrom sxfOrderClearingItem) {
		if(findById(sxfOrderClearingItem.getId())== null) {
			return ResponseData.fail("没有找到对应记录");
		}
		SxfOrderClearingItem entity = transformationFrom(sxfOrderClearingItem);
		entity.setId(sxfOrderClearingItem.getId());
		this.updateById(entity);
		return ResponseData.success("修改成功");
	}

	public SxfOrderClearingItem transformationFrom(SxfOrderClearingItemFrom sxfOrderClearingItem) {
		SxfOrderClearingItem entity = new SxfOrderClearingItem();
		entity.setMerchantCode(sxfOrderClearingItem.getMerchantCode());
		entity.setClearingType(sxfOrderClearingItem.getClearingType());
		entity.setClearingTime(sxfOrderClearingItem.getClearingTime());
		entity.setAmount(sxfOrderClearingItem.getAmount());
		entity.setAlipayAccount(sxfOrderClearingItem.getAlipayAccount());
		entity.setRemark(sxfOrderClearingItem.getRemark());
		entity.setType(sxfOrderClearingItem.getType());
		entity.setCreateTime(sxfOrderClearingItem.getCreateTime());
		entity.setModifyTime(sxfOrderClearingItem.getModifyTime());
		return entity;
	}

	public SxfOrderClearingItemFrom transformationBean(SxfOrderClearingItem sxfOrderClearingItem) {
		SxfOrderClearingItemFrom from = new SxfOrderClearingItemFrom();
		from.setMerchantCode(sxfOrderClearingItem.getMerchantCode());
		from.setClearingType(sxfOrderClearingItem.getClearingType());
		from.setClearingTime(sxfOrderClearingItem.getClearingTime());
		from.setAmount(sxfOrderClearingItem.getAmount());
		from.setAlipayAccount(sxfOrderClearingItem.getAlipayAccount());
		from.setRemark(sxfOrderClearingItem.getRemark());
		from.setType(sxfOrderClearingItem.getType());
		from.setCreateTime(sxfOrderClearingItem.getCreateTime());
		from.setModifyTime(sxfOrderClearingItem.getModifyTime());

		return from;
	}

	
	public SxfOrderClearingItemFrom findById(String id) {
		SxfOrderClearingItem entity = this.getOne(new QueryWrapper<SxfOrderClearingItem>().lambda()
				.eq(SxfOrderClearingItem::getId, id)
				);
		if(entity == null) return null;
		return transformationBean(entity);
	}
	
	public ResponseData remove(String id) {
		if(findById(id)== null) {
			return ResponseData.fail("没有找到对应记录");
		}
		SxfOrderClearingItem sxfOrderClearingItem = new SxfOrderClearingItem();
		sxfOrderClearingItem.setId(id);
		this.updateById(sxfOrderClearingItem);
		return ResponseData.success("删除成功");
	}
	
	public IPage pageList(Integer page, Integer size, SxfOrderClearingItemFrom ibean) {
		return this.page(new Page(page, size), new QueryWrapper<SxfOrderClearingItem>().lambda()
				.eq(StringUtils.isNotEmpty(ibean.getMerchantCode()), SxfOrderClearingItem::getMerchantCode, ibean.getMerchantCode())
				.eq(ibean.getClearingType() != null, SxfOrderClearingItem::getClearingType, ibean.getClearingType())
				.eq(StringUtils.isNotEmpty(ibean.getClearingTime()), SxfOrderClearingItem::getClearingTime, ibean.getClearingTime())
				.eq(ibean.getAmount() != null, SxfOrderClearingItem::getAmount, ibean.getAmount())
				.eq(StringUtils.isNotEmpty(ibean.getAlipayAccount()), SxfOrderClearingItem::getAlipayAccount, ibean.getAlipayAccount())
				.eq(StringUtils.isNotEmpty(ibean.getRemark()), SxfOrderClearingItem::getRemark, ibean.getRemark())
				.eq(ibean.getType() != null, SxfOrderClearingItem::getType, ibean.getType())
				.eq(ibean.getCreateTime() != null, SxfOrderClearingItem::getCreateTime, ibean.getCreateTime())
				.eq(ibean.getModifyTime() != null, SxfOrderClearingItem::getModifyTime, ibean.getModifyTime())
				);
	}
}
